/*
 * File Name: BufferStream.h
 *
 * Created on: 2021-01-28
 * Author: glendy ganby@163.com
 *
 * Last Modified: 2021-01-28
 * Description:
 */

#ifndef _BUFFERSTREAM_H_
#define _BUFFERSTREAM_H_

#include <string>
#include <stdint.h>

namespace miniproto
{

class BufferStream
{
public:
	BufferStream(void *data, int size);
	~BufferStream();

	void *read_ptr();
	int left_read_size();
	int has_read_size();
	bool read_buffer(int need_size);
	bool read_tag(uint32_t *tag);
	bool read_varint64(uint64_t *val);
	bool read_string(::std::string *val, const uint64_t size);
	bool read_double(double *val);
	bool read_float(float *val);

	void *write_ptr();
	int left_write_size();
	int has_write_size();
	bool write_buffer(int write_size);
	bool write_tag(const uint32_t tag);
	bool write_varint64(const uint64_t val);
	bool write_string(const ::std::string *val);
	bool write_double(const double val);
	bool write_float(const float val);

private:
	uint8_t *data_;
	int total_size_;
	uint8_t *wbegin_;
	uint8_t *wend_;
	uint8_t *rbegin_;
	uint8_t *rend_;
};

} // namespace miniproto

#endif //_BUFFERSTREAM_H_
